package com.leyou.item.mapper;

import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface BrandMapper extends Mapper<Brand> {
    @Insert("INSERT INTO   tb_category_brand  ( category_id ,  brand_id ) VALUES (#{cid}, #{id})")
    void insertCategoryBrand(@Param("cid")Long cid,@Param("id")Long id);
    @Delete("delete from tb_brand where id = #{id}")
    int deleteBrandById(@Param("id")Long id);
    @Delete("delete from tb_category_brand where brand_id = #{id}")
    int deleteMiddleById(@Param("id")Long id);

    @Update("<script>"+"delete from tb_category_brand    WHERE brand_id =  #{bid} and category_id  not in " + "  <foreach collection='ids' item='id' separator=',' open='(' close=')'>" + " #{id}" + "</foreach>"+"</script>")
    void updateCategoryBrand(@Param("ids")Object[] ids, @Param("bid") Long bid);
    @Select("SELECT b.* FROM tb_brand b LEFT JOIN tb_category_brand cb ON b.id = cb.brand_id WHERE cb.category_id = #{cid}")
    List<Brand> queryByCategoryId( @Param("cid") Long cid);
}
